<?php
function checkLogin()
{
	$usuario = null;
	
	if (!isset($_SESSION['auth_login'])) {
		header('Location: '.WEB_ROOT.'login.php');
		exit;
	} else {
		$usuario = $_SESSION['auth_login'];
	}
	
	return $usuario;
}
function dataAtual() {
    date_default_timezone_set('America/Sao_paulo');
	return date("Y-m-d");
}
function dataHoraAual() {
    date_default_timezone_set('America/Sao_paulo');
	return date("Y-m-d H:i:s");
}

function checkLoginAdmin()
{
	$usuario = null;
	
	if ($_SESSION['admin_login'] == null) {
                $msgError = " Você não possui acesso de administrador.";
		header('Location: '.WEB_ROOT.'index.php?msgError='.$msgError.'');
		exit;
	} else {
		$usuario = $_SESSION['admin_login'];
	}
	
	return $usuario;
}
//
function registerDataBase($dtBanco){
     $data = explode("/",$dtBanco); //[16][04][2011]
    $data = array_reverse($data); //[2011][04][16]
    $dtBanco = implode("-", $data); //2011-04-16

       return $dtBanco;
   }

function setMaskDate($timestamp, $format = '', $retND = true) {
	if ($format == '') {
		//$format = 'd/m/Y H:i';
		$format = 'd/m/Y';
	}

	if ($timestamp) {
		$timestamp = strtotime($timestamp);
	}

	if (!$timestamp) {
		if ($retND) {
			return 'N/D';
		} else {
			return null;
		}
	} else {
		return date($format, $timestamp);
	}
}

function setMaskCNPJ($CNPJ) {
	// 03.847.655/0001-98
	$retira = array(".", " ", "(", ")", "-", "/");
	$CNPJ = str_replace($retira, "", $CNPJ);
	return substr($CNPJ,0,2).".".substr($CNPJ,2,3).".".substr($CNPJ,5,3)."/".substr($CNPJ,8,4)."-".substr($CNPJ,12,2);
}


function setMaskCPF($CPF) {
	$retira = array(".", " ", "(", ")", "-", "/");
	$CPF = str_replace($retira, "", $CPF);
	return substr($CPF,0,3).".".substr($CPF,3,3).".".substr($CPF,6,3)."-".substr($CPF,9,2);
}

function setMaskCEP($CEP) {
	if (trim($CEP) == '')
	{
		return '';
	}
	
	$retira = array(".", " ", "(", ")", "-", "/");
	$CEP = str_replace($retira, "", $CEP);
	return substr($CEP,0,5)."-".substr($CEP,5,3);
}

?>